
#include <iostream>
#include <thread>
#include <chrono>
 
using namespace std;
 
void func1() {
    for (int i = 0; i < 15; i++) {
        cout << "Hello from func1 Num: " << i << endl;
        this_thread::sleep_for(chrono::milliseconds(500));
    }
}
 
void func2() {
    for (int i = 0; i < 15; i++) {
        cout << "Hello from func2 Num: " << i<< endl;
        this_thread::sleep_for(chrono::milliseconds(500));
    }
}
 
int main() {
    thread t1(func1);
    thread t2(func2);
 
    t2.detach(); // t2成为一个独立线程// 主线程等待一段时间，然后退出 
    cout<<"t2 is runed detach"<<endl;
    t1.join(); // 等待t1执行完毕
    this_thread::sleep_for(chrono::seconds(3));
    cout << "Main thread exits" << endl;
 
    return 0 ;
}
